package com.zy.fee.roadpark.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.zy.fee.roadpark.R;
import com.zy.fee.roadpark.model.M_Message;
import com.zygk.library.adapter.BaseListAdapter;
import java.util.List;

/**
 * Created by Administrator on 2018/9/13 0013.
 */

public class MessageAdapter extends BaseListAdapter<M_Message> {
  public MessageAdapter(Context context, List<M_Message> list) {
    super(context, list);
  }

  @Override public View getView(final int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    if (convertView == null) {
      convertView = mInflater.inflate(R.layout.item_message, null, false);
      holder = new ViewHolder(convertView);

      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }

    M_Message m = getData().get(position);
    holder.tvMsg.setText(m.getContentText());
    holder.tvTime.setText(m.getAddDatatime());
    if (m.getState() == 0) {
      holder.ivUnread.setVisibility(View.VISIBLE);
    } else {
      holder.ivUnread.setVisibility(View.INVISIBLE);
    }
    if (position == getData().size() - 1) {
      holder.line.setVisibility(View.GONE);
    } else {
      holder.line.setVisibility(View.VISIBLE);
    }

    return convertView;
  }

  static class ViewHolder {
    @BindView(R.id.iv_unread) ImageView ivUnread;
    @BindView(R.id.tv_msg) TextView tvMsg;
    @BindView(R.id.tv_time) TextView tvTime;
    @BindView(R.id.line) View line;

    ViewHolder(View view) {
      ButterKnife.bind(this, view);
    }
  }
}
